package com.example.consumer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import javax.jms.JMSException;
import javax.jms.TextMessage;
import javax.jms.Topic;

@Component
public class TopicMessageListener {

    private Topic testTopic;

    @Autowired
    public void setTestTopic(Topic testTopic) {
        System.out.println("注入testTopic:" + testTopic);
        this.testTopic = testTopic;
    }

    @JmsListener(destination = "#{testTopic.topicName}", containerFactory = "jmsListenerContainerFactoryForTopic")
    public void onMessage(TextMessage message) throws JMSException {
        System.out.println("TopicMessageListener收到topic消息：" + message.getText());
    }
}
